define([
        'underscore',
        'app/service/GeneralServices',
        'app/utils/WebUtils',
        'app/utils/CommonUtils'
        ], function (
		_,
		GeneralServices,
		WebUtils
    ) {
	
    var s = {};
	
    var roomPwdSwitch = function(needShow, useruuid, roomuuid){
    	var p = {
				useruuid:useruuid,
				roomuuid:roomuuid
			};
    	if(needShow){
    		p.pwd = "1";
    	}else{
    		p.pwd = "0";
    	}
    	GeneralServices.room_pwd_switch(p,function(resp){
			if(resp.status != "200"){
				WebUtils.alert("更新操作没有成功，请重试");
				return;
			}
			$.setUrlParam("tab","5");
		});
    };
	s.initPwdPanel=function(pwd, useruuid, roomuuid){
		var hasPwd = !$.isNullStr(pwd);
		
		if(hasPwd){
			$(".wjt_room_pwd_operation").show();
			$("#wjt_room_pwd").val(pwd);
			$(".room-pwd-ratio-options-group").find("label").removeClass("am-active");
			$(".room-pwd-ratio-options-group").find("label:last").addClass("am-active");
			$(".room-pwd-ratio-options-group").find("label").find("input").removeAttr("checked");
			$(".room-pwd-ratio-options-group").find("label:last").find("input").prop("checked","checked");
		}else{
			$(".wjt_room_pwd_operation").hide();
			$("#wjt_room_pwd").val("");
			$(".room-pwd-ratio-options-group").find("label").removeClass("am-active");
			$(".room-pwd-ratio-options-group").find("label:first").addClass("am-active");
			$(".room-pwd-ratio-options-group").find("label").find("input").removeAttr("checked");
			$(".room-pwd-ratio-options-group").find("label:first").find("input").prop("checked","checked");
		}
		
		var $radios = $('[name="room-pwd-ratio-options"]');
	    $radios.on('change',function() {
	    	if($radios.filter(':checked').val() == "1"){
	    		roomPwdSwitch(true, useruuid, roomuuid);
	    	}else{
	    		roomPwdSwitch(false, useruuid, roomuuid);
	    	}
	    });
	    
	    $("#wjt_room_pwd_gen_btn").click(function(){
	    	roomPwdSwitch(true, useruuid, roomuuid);
	    });
		
	};
	
	
	return s;

});
